package com.zking.seckillpro.service.impl;

import com.zking.seckillpro.model.User;
import com.zking.seckillpro.service.IRedisService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisServiceImpl implements IRedisService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public void setUserToRedis(String token, User user) {
        redisTemplate.opsForValue().set("user:"+token,user,7200L, TimeUnit.SECONDS);
    }

    @Override
    public User getUserByToken(String token) {

        return (User) redisTemplate.opsForValue().get("user:"+token);
    }
}
